package com.study.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.study.services.PurchaseService;

@Controller
public class PurchaseController {
	@Autowired
	PurchaseService service;
	
	
	
	
	
	/**
	 * 查询所有采购单
	 * @return
	 */
	@GetMapping("/detailList")
	@ResponseBody
	public ModelAndView purchase() {
		ModelAndView mv = new ModelAndView("/goods/detailList");
		return mv;
	}
	
	/**
	 * 条件查询
	 * @return
	 */
	@PostMapping("/detailList")
	@ResponseBody
	public String selectByPage(HttpSession session) {
		Integer userid = (Integer) session.getAttribute("useid");
		List<JSONObject> list = service.selectBySel(1, 10, "",userid);
		PageInfo<JSONObject> pager = new PageInfo<JSONObject>(list);
        String json = JSONObject.toJSONString(pager);
		System.out.println(json);
		return json;
	}
	
	/**
	 * 带条件查询
	 * @return
	 */
	@PostMapping("/detailList2")
	@ResponseBody
	public String getForm3(String input,
			String selects,
			int currentPage,
			int pagesize,
			HttpSession session,HttpServletRequest request) {
		System.out.println(selects+"===="+input);
		Integer userid = (Integer) session.getAttribute("useid");
		List<JSONObject> list = service.selectBySel(currentPage, pagesize, input.trim(),userid);
		PageInfo<JSONObject> pager = new PageInfo<JSONObject>(list);
		String json = JSONObject.toJSONString(pager);
		return json;
	}
	
}
